;
(function() {
	function getSheet() {
		var doc = document,
			head = doc.getElementsByTagName("head")[0],
			styles = head.getElementsByTagName("style"),
			style, media;
		if (styles.length == 0) { //如果不存在style元素则创建
			if (doc.createStyleSheet) { //ie
				doc.createStyleSheet();
			} else {
				style = doc.createElement('style'); //w3c
				style.setAttribute("type", "text/css");
				head.insertBefore(style, null)
			}
		}
		style = styles[0];
		media = style.getAttribute("media");
		if (media === null && !/screen/i.test(media)) {
			style.setAttribute("media", "all");
		}
		return style;
	};

	function clearSheet() {
		var style = getSheet();
		style.parentNode.removeChild(style);
	};

	function getSheetText() {
		var style = getSheet();
		return style.innerHTML;
	};
	// var css_files = [];
	// //lib域的样式文件表
	// var _css_info_prefix = "GET CSS FILE LIST:";
	// var cross_iframe = document.getElementById("cross_iframe");
	// messenger = new Messenger('cross_iframe', 'O2O_lib');
	// messenger.addTarget(cross_iframe.contentWindow, "cross_iframe");
	// messenger.listen(function(msg) {
	// 	if (msg.indexOf(_css_info_prefix) !== -1) {
	// 		var res = msg.split(_css_info_prefix);
	// 		var css_lib_list = JSON.parse(res[1]);
	// 		css_files = css_files.concat(css_lib_list);

	// 		css_files = css_files.map(function(name) {
	// 			return name.replace("r_text!", "r_css!") + "?__no_cache__=true&__reload_random__=" + Math.random()
	// 		});

	// 		console.log(css_files);
	// 		clearSheet();
	// 		require(css_files, function() {
	// 			alert("success", "样式重载完成");
	// 		});
	// 	}
	// });
	// window.__reload_requirer_css__ = function() {
	// 	//当前域的样式文件表
	// 	css_files.length = 0;
	// 	LS.each(function(name) {
	// 		if (name.slice(-4) === ".css") {
	// 			css_files.push(name);
	// 		}
	// 	});
	// 	messenger.send(_css_info_prefix);
	// };
	window.__reload_requirer_css__ = function() {
		var css_text = getSheetText();
		var css_text = css_text.split("/*CSS-FILE-PATH:");
		var css_files = [];
		css_text.forEach(function(css_text_item) {
			var end_index = css_text_item.indexOf(":END-PATH*/")
			if (end_index !== -1) {
				css_files.push(css_text_item.substr(0, end_index));
			}
		});
		// console.log(css_files);
		css_files = css_files.map(function(name) {
			return "r_css!" + name + ".css?__no_cache__=true&__reload_random__=" + Math.random()
		});
		clearSheet();
		require(css_files, function() {
			alert("success", "样式重载完成");
		});
	};
	__reload_requirer_css__();
}());